<?php
namespace app\common\model;
use think\Model;

class LotteryUserShareNum extends Model
{
	
	/**
     * //添加 分享记录
     * @param type $user_id
     * @param type $new_pwd
     * @return type
     */
	public function addRow($uid,$activity_id,$lottery_sid)
    {
		if( !$activity_id || !$lottery_sid || $uid == $lottery_sid){
			return false;
		}
		// 如果是自己 则不添加
		if( model('user')->where('id',$lottery_sid)->value('openid') == $uid ){
			return false;
		}
		
		$lottery = model('lottery')->where('id',$activity_id)->find();
		if(!$lottery){
			return false;
		}
		if($lottery['share_num'] < 1){
			return false;
		}
		
    	//如果已经添加过
		$result = model('lottery_user_share_num')->where('activity_id',$activity_id)
				->where('uid',$lottery_sid)->where('sid',$uid)->find();
				
		if($result){ return false; }
		
		for ($i=0; $i < $lottery['share_num']; $i++) {
			model('lottery_user_share_num')->insert([
				"activity_id"=>$activity_id,
				"uid"=>$lottery_sid,
				"sid"=>$uid
			]);
		}
    }
	
}
